package com.diipo.weibo.adapter;

import java.util.ArrayList;
import java.util.LinkedList;

import com.diipo.weibo.AsyncImageLoader;
import com.diipo.weibo.R;
import com.diipo.weibo.entity.Contacts;
import com.diipo.weibo.entity.ContactsList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ContactsItemAdapter extends BaseAdapter{
	
	private ArrayList<String> contactsArrayList = new ArrayList();
	private Context mctx;

	public ContactsItemAdapter(ArrayList<String> arraylist, Context mctx) {
		super();
		this.contactsArrayList = arraylist;
		this.mctx = mctx;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return contactsArrayList == null ? 0 : contactsArrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return contactsArrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ContactsItem item = null;
		if (convertView == null) {
			item = new ContactsItem();
			LayoutInflater inflater = LayoutInflater.from(mctx);
			convertView = View.inflate(mctx, R.layout.contacts_item, null);
//			item.icon = (ImageView) convertView.findViewById(R.id.contacts_item_icon);
			item.name = (TextView) convertView.findViewById(R.id.contacts_item_name);
			convertView.setTag(item);
		}
		
//		convertView.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
////				Log.e(" pyb ", " LetterItemAdapter getView() called ,position = " + position);
//			}
//		});
		item = (ContactsItem) convertView.getTag();
		String username = contactsArrayList.get(position);
//		asyncImageLoader.loadPortrait(contactsList.getId(), contactsList.getProfile_picture(), item.icon);
		item.name.setText(username);
//		Log.e(" pyb ", " LetterItemAdapter getView() called ,position = " + position);
		return convertView;
	}

}
